﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BowlingGame.Tests
{
    [TestClass]
    public class GameTests
    {
        private Game _game;

        [TestInitialize]
        public void SetUp()
        {
            _game = new Game();
        }

        [TestMethod]
        public void TestScoreNoThrows()
        {
            Assert.AreEqual(0, _game.Score);
        }

        [TestMethod]
        public void TestScoreOneThrows()
        {
            _game.AddThrow(1);
            Assert.AreEqual(1, _game.Score);
            Assert.AreEqual(0, _game.CurrentFrameIndex);
        }

        [TestMethod]
        public void TestScoreTwoThrows()
        {
            _game.AddThrow(1);
            _game.AddThrow(7);
            Assert.AreEqual(7 + 1, _game.Score);
            Assert.AreEqual(1, _game.CurrentFrameIndex);
        }

        [TestMethod]
        public void TestScoreForFrame()
        {
            _game.AddThrow(1);
            _game.AddThrow(7);
            _game.AddThrow(2);
            _game.AddThrow(6);
            _game.AddThrow(5);
            Assert.AreEqual(7 + 1, _game.GetScoreForFrame(0));
            Assert.AreEqual(7 + 1 + 2 + 6, _game.GetScoreForFrame(1));
            Assert.AreEqual(7 + 1 + 2 + 6 + 5, _game.GetScoreForFrame(2));
            Assert.AreEqual(7 + 1 + 2 + 6 + 5, _game.Score);
            Assert.AreEqual(2, _game.CurrentFrameIndex);
        }

        [TestMethod]
        public void TestSpare()
        {
            _game.AddThrow(3);
            _game.AddThrow(7);
            _game.AddThrow(2);
            Assert.AreEqual(7 + 3 + 2, _game.GetScoreForFrame(0));
            Assert.AreEqual(7 + 3 + 2 + 2, _game.GetScoreForFrame(1));
            Assert.AreEqual(7 + 3 + 2 + 2, _game.Score);
        }

        [TestMethod]
        public void TestSimpleStrike()
        {
            _game.AddThrow(10);
            _game.AddThrow(3);
            _game.AddThrow(6);
            Assert.AreEqual(2, _game.CurrentFrameIndex);
            Assert.AreEqual(19, _game.GetScoreForFrame(0));
            Assert.AreEqual(28, _game.Score);
        }

        [TestMethod]
        public void TestPerfectGame()
        {
            for (var i = 0; i < 12; i++)
                _game.AddThrow(10);

            Assert.AreEqual(300, _game.Score);
            Assert.AreEqual(9, _game.CurrentFrameIndex);
        }

        [TestMethod]
        public void TestSampleGame()
        {
            _game.AddThrow(1);
            _game.AddThrow(4);
            _game.AddThrow(4);
            _game.AddThrow(5);
            _game.AddThrow(6);
            _game.AddThrow(4);
            _game.AddThrow(5);
            _game.AddThrow(5);
            _game.AddThrow(10);
            _game.AddThrow(0);
            _game.AddThrow(1);
            _game.AddThrow(7);
            _game.AddThrow(3);
            _game.AddThrow(6);
            _game.AddThrow(4);
            _game.AddThrow(10);
            _game.AddThrow(2);
            _game.AddThrow(8);
            _game.AddThrow(6);
            Assert.AreEqual(133, _game.Score);
        }

        [TestMethod]
        public void TestHeartBreak()
        {
            for (var i = 0; i < 11; i++)
                _game.AddThrow(10);

            _game.AddThrow(9);
            Assert.AreEqual(299, _game.Score);
        }

        [TestMethod]
        public void TestTenthFrameSpare()
        {
            for (var i = 0; i < 9; i++)
                _game.AddThrow(10);

            _game.AddThrow(9);
            _game.AddThrow(1);
            _game.AddThrow(1);
            Assert.AreEqual(270, _game.Score);
        }
    }
}